package com.stylefeng.guns.biz.wxchat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.biz.hot.model.HotList;
import com.stylefeng.guns.biz.wxchat.model.TWechatUser;
import com.stylefeng.guns.biz.wxchat.service.ITWechatUserService;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;

/**
 * 微信用户控制器
 *
 * @author fengshuonan
 * @Date 2018-06-14 06:35:39
 */
@Controller
@RequestMapping("/tWechatUser")
public class TWechatUserController extends BaseController {

    private String PREFIX = "/app/tWechatUser/";

    @Autowired
    private ITWechatUserService tWechatUserService;

    /**
     * 跳转到微信用户首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "tWechatUser.html";
    }

    /**
     * 跳转到添加微信用户
     */
    @RequestMapping("/tWechatUser_add")
    public String tWechatUserAdd() {
        return PREFIX + "tWechatUser_add.html";
    }

    /**
     * 跳转到修改微信用户
     */
    @RequestMapping("/tWechatUser_update/{tWechatUserId}")
    public String tWechatUserUpdate(@PathVariable Integer tWechatUserId, Model model) {
        TWechatUser tWechatUser = tWechatUserService.selectById(tWechatUserId);
        model.addAttribute("item",tWechatUser);
        LogObjectHolder.me().set(tWechatUser);
        return PREFIX + "tWechatUser_edit.html";
    }

    /**
     * 获取微信用户列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String appid) {
    	
    	EntityWrapper<TWechatUser> wrapper=new EntityWrapper<>();
    	wrapper.eq("app_id", appid);
    	
        return tWechatUserService.selectList(wrapper);
    }

    /**
     * 新增微信用户
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(TWechatUser tWechatUser) {
        tWechatUserService.insert(tWechatUser);
        return SUCCESS_TIP;
    }

    /**
     * 删除微信用户
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer tWechatUserId) {
        tWechatUserService.deleteById(tWechatUserId);
        return SUCCESS_TIP;
    }

    /**
     * 修改微信用户
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(TWechatUser tWechatUser) {
        tWechatUserService.updateById(tWechatUser);
        return SUCCESS_TIP;
    }

    /**
     * 微信用户详情
     */
    @RequestMapping(value = "/detail/{tWechatUserId}")
    @ResponseBody
    public Object detail(@PathVariable("tWechatUserId") Integer tWechatUserId) {
        return tWechatUserService.selectById(tWechatUserId);
    }
}
